<%@ page language="java" import="java.util.*"  pageEncoding="utf-8"%>
<%
String path=request.getContextPath();
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.or/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<base href="<%=basePath %>">
<title>规则配置</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
<script type="text/javascript">

$(document).ready(function() {
	isReadyIframe();
	
	//添加/编辑成功返回该页面的提示
	<%if(null != request.getAttribute("flag")){
		if("edit".equals(request.getAttribute("flag").toString())){%>	
			$.message("success","修改成功");
		<%}
		if("add".equals(request.getAttribute("flag").toString())){%>
			$.message("success","添加成功");
		<%}
	}%>
	
	queryRuleAgent(1);
});


function isReadyIframe(){
	var iframe = $(window.parent.document).find("#iframe").length;
	if(iframe==0){
		window.location.href="<%=basePath%>index.jsp";
	}
}
//点击“选择(合作伙伴)”
function openChannelPageDiv(){
	queryChannelInfo(1);
}

//为查询合作伙伴 拼接参数
function queryChannelInfo(pageIndex){
	var channelCode = $.trim($('#channelCode_choose').val());
	var channelName = $.trim($('#channelName_choose').val());
	
	loadChannelInfo({current:pageIndex,size:8,channelCode:channelCode,channelName:channelName});
}

//加载合作伙伴
function loadChannelInfo(param){
	$.openLoading();
	$.ajax({
		url : "<%=path%>/nlifePlanConfig/queryChannelInfoPageByCriteria?"+new Date().getTime(),
		type : 'POST',
		async : true,
		data:param,
		dataType:'json',
		success:function(page){
			$.closeLoading();
			if($.validate(page))return;

			var radioObj ="<input class='input_fxk' name='radioRuleAgent' type='radio' value=''>";
			var fieldNames = "channelCode,channelName";
			var tableContent = creatTable1(fieldNames,page,radioObj);
			var tableObj = $("#channelInfoTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			var strPage = creatChannelPage2(param.current,6,page.maxPage,"42");
			var pageDIV = $("#channelInfoPageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
			$('#channelInfoDiv').OpenDiv();
			
			bindradio();
		}
	});
}  

//点击“确定”按钮，选择合作伙伴
function chooseChannelInfo(){
	var selected = $("input[name='radioRuleAgent']:checked");
	if(selected.length==0){
		$.message("error", "请选择一个合作伙伴");
		return;
	}
	var channelCode = selected.parent().parent().children(" td:eq(1)").html();
	$('#partnerNo').val(channelCode);
	
	closeChannelInfoDiv();
}

//关闭 选择合作伙伴 弹出层
function closeChannelInfoDiv(){
	$("#channelInfoDiv").CloseDiv();	
	
	$('#channelCode_choose').val("");
	$('#channelName_choose').val("");
}

//为查询规则 拼接参数
function queryRuleAgent(pageIndex){
	var partnerNo = $.trim($('#partnerNo').val());
	var ruleName = $.trim($('#ruleName').val());
	var ruleId = $.trim($('#ruleId').val());
	var userCode=$.trim($('#userCode').val());
	var checkStatus=$.trim($('#checkStatus').val());
	
	queryRuleAgentList({current:pageIndex,size:10,partnerNo:partnerNo,ruleName:ruleName,ruleId:ruleId,userCode:userCode,checkStatus:checkStatus});
}
function resetQueryRuleAgentnCriteria(){
	$("#queryRuleAgentCriteriaTable input[type!='button']").val("");
}
var exportflag=false;
//加载投保规则
function queryRuleAgentList(param){
	$.openLoading();
	$.ajax({
			url : "<%=path%>/ruleAgentConfig/queryRuleAgentPage?"+new Date().getTime(),
			type : 'POST',
			async : true,
			dataType:'json',
			data:param,
			success : function(page) {
				$.closeLoading();
				if($.validate(page))return;
				var flag=page.obj 
				var firstbutton ='';
				if(flag){
					 firstbutton ="<input class='input_fxk' name='radioRuleAgent' type='radio' value='#'>@<input class='input_fxk' name='checkRule' type='checkBox' value='#'>";
				}else{
					 firstbutton ="<input class='input_fxk' name='radioRuleAgent' type='radio' value='#'>"
				}
				var lastbutton = "<a href='javascript:void(0)' onClick='editRuleAgent(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delRuleAgent(this);return false'>删除</a>";
				var tableContent = creatTable1("id@TDH,ruleId,ruleName,userCode,ruleAgentDesc,plan,premium,effDate,termDate,status?[{0:'无效'};{1:'有效'}]",page,firstbutton,lastbutton);
				var tableObj = $("#rulelistTable");
				tableObj.find("tbody").remove();
				tableObj.append(tableContent);
				var strPage = creatChannelPage(param.current,6,page.maxPage,"92");
				var pageDIV = $("#ruleAgentPageDIV");
				bindradio();
				pageDIV[0].innerHTML="";
				exportflag=flag;
				pageDIV.append(strPage);
			}
		});
}

function bindradio(){
	$("input[type='radio']").click(function(){
		$("input[name='radioRuleAgent']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");

   	});
}

//点击“删除(规则)”
function delRuleAgent(ruleAgent){
	$.dialog({
		type: "warn",
		content: "您确定要删除该用户二维码吗？",
		onOk: function() {
			$.openLoading();
			var delTr = $(ruleAgent).parent('td').parent('tr')[0];
			var planflag=1;
			var partflag=5;
			var id = delTr.childNodes[planflag].innerHTML;
			$.ajax({
				url : "<%=path%>/ruleAgentConfig/delRuleAgent?"+new Date().getTime(),
				type: "POST",
				async:true,
				dataType: "json",
				data:{
					ruleAgentId:id,
				},
				success: function(data) {
					$.closeLoading();
					if($.validate(data))return;
					queryRuleAgent(1);
				}
			});
		}
	});
}
//新增(二维码),跳转至新增方案 页面
function addRuleAgent(){
	window.location.href="<%=path%>/ruleAgentConfig/toAddRuleAgent";
}

//编辑(二维码),跳转至 编辑方案 页面
function editRuleAgent(ruleAgent){
	var delTr = $(ruleAgent).parent('td').parent('tr')[0];
	var ruleAgentId = delTr.childNodes[1].innerHTML;
	window.location.href="<%=path%>/ruleAgentConfig/toeditRuleAgent?ruleAgentId="+ruleAgentId;
}

//二维码下载
function downloadQRCode(){
	var selected = $("input[name='radioRuleAgent']:checked");
	if(selected.length==0){
		$.message("error", "请选择一个用户二维码");
		return;
	}
	var ruleAgentId = selected.parent('td').parent('tr')[0].childNodes[1].innerHTML;
	window.location.href='<%=path%>/ruleAgentConfig/downloadQRCode?ruleAgentId='+ruleAgentId;
}
function bindredio(){
	$("input[name='radioTemple']").click(function(){
		$("input[name='radioTemple']").parent().parent().removeClass("table_highlighter");
		$(this).parent().parent().addClass("table_highlighter");

   	});
}
</script>
</head>
<body>
	<div class="current">
		<table class="current_table_1">
			<tbody>
				<tr class="f2">
				<td><img src="./images/current_1.jpg"></td>
				 <td class="current_table_1_td">
                   <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                     <span style=" color:#136bab; ">界面出单管理
                     <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>录单二维码管理
                 </span>
                 </td>
                 <td><img src="./images/current_3.jpg"></td>
				</tr>
			</tbody>
		</table>
	</div>
	<table class="table_02" id="table">
		<tr>
			<td>
				<table class="search_table" id="queryRuleAgentCriteriaTable">
					<tr height="30px">
						<td width="32%" height="30">
							<div style="display: inline-block;">
								合作伙伴代码：
								<input name="txt3"  id="partnerNo" value="" readonly="readonly" style="background: #ccc;" class="input_text">
								<input type="button"  class="input_button_1" id="openChannelPageDivBtn" value="选择" onClick="openChannelPageDiv()"/>
							</div>
						</td>
						<td width="23%" height="30">规则名称：
							&nbsp;<input name="txt3" id="ruleName" value="" class="input_text" />
						</td>
					</tr>
					<tr height="25px">
						<td width="25%" height="30">&nbsp;代理人编码：
							<input name="txt3" id="userCode" value=""  class="input_text" />
						</td>
						<td width="23%" height="30">&nbsp;规则Id：
							&nbsp;<input name="txt3" id="ruleId" value="" class="input_text" />
						</td>
						<td width="25%" height="30">状&nbsp;&nbsp;态：&nbsp;
	                  	<select id="checkStatus"  class="select_1" style="visibility: visible;">
	                  		<option value="">----请选择----</option>
	                  		<option value="1">有效</option>
	                  		<option value="0">无效</option>
	                  	</select>
	                    </td>
						<td width="30%" height="30">
							<input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryRuleAgent(1)"/>&nbsp;
							<input type="button" value="重置" onClick="resetQueryRuleAgentnCriteria()" class="input_button_1" />							
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="search_table">
					<tr height="30px">
						<td width="100%" height="30">
							 <input type="button"  class="input_button_1" id="searchBtn" value="新增" onClick="addRuleAgent()"/>&nbsp;
							 <input type="button"  class="input_button_2" id="downloadQR" value="二维码下载" onClick="downloadQRCode()"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table id="rulelistTable"  class="content_table_1">
					<thead>
						<tr class="f1">
		                  <th style="width:3%">选择</th>
		                  <th style="width:5%;display: none">规则编码</th>
		                  <th style="width:5%">规则ID</th>
		                  <th style="width:5%">规则名称</th>
		                  <th style="width:8%">代理人编码</th>
		                  <th style="width:6%">二维码描述</th>
		                  <th style="width:6%">方案</th>
						  <th style="width:6%">保费</th>
		                  <th style="width:7%">有效起期</th>
		                  <th style="width:7%">有效止期</th>
		                  <th style="width:6%">状态</th>
		                  <th style="width:4%">操作</th>
		              	</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
				<div id="ruleAgentPageDIV"  class="page"></div>
			</td>
		</tr>
	</table>
	
	<!-- 选择 合作伙伴 div-->
  	<div id="channelInfoDiv" style="display:none;width:90%;text-align: center;">
		<div class="table_title_div">
				<table class="table_title" style='width:100%;height: 20px;'>
					<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeChannelInfoDiv()"/></td>
					</tr>
				</table>
		</div>
		<table class="table_02" style="width:98%">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
								合作伙伴代码：<input name="txt3"  id="channelCode_choose" class="input_text" />&nbsp;&nbsp;
								合作伙伴名称：<input name="txt3" id="channelName_choose" class="input_text" />&nbsp;&nbsp;
								<input type="button"  class="input_button_1" value="查询" onClick="queryChannelInfo(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="channelInfoTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="channelInfoPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center">
		   <input type="button" value="确定" onclick="chooseChannelInfo()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		   <input type="button" value="取消" onclick="closeChannelInfoDiv()" class="input_button_3"/>
		</div>
	</div>	
</body>
</html>